package pers.kuroko.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import pers.kuroko.entity.Login;
import pers.kuroko.service.LoginService;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller//注解，表明是Controller
@RequestMapping("loginController")
public class LoginController {
    @Autowired
    @Qualifier("loginService")
    LoginService loginService;
    @RequestMapping(value = "homePage")
    public String homePage(Login login, Map<String, Object> map, HttpServletRequest request) {
        String userName = request.getParameter("username");
//        System.out.print(userName);
        int i = loginService.doLogin(login);
        if(!userName.equals(null) && i > 0 ){
//            //把用户数据保存在session域对象中
            request.getSession().setAttribute("sessionname",userName);
            map.put("login", login);
            System.out.print("存储成功");
            return "redirect:/index.jsp";
        }else {
            return "error";
        }
    }

}
